var sorl = sorl || {};
sorl.curator = sorl.curator || {};

sorl.curator.cont = {
    init: function() {
        var inp = YAHOO.util.Selector.query("input[name=_continue]");
        for (var i=0; i<inp.length; i++){
            inp[i].setAttribute("type", "button");
            YAHOO.util.Event.on(inp[i], 'click', sorl.curator.cont.submit)
        }
    },
    submit: function(ev) {
        if(tinyMCE){
            tinyMCE.triggerSave(0,1);
        }
        var postArray = new Array();
        var fields = YAHOO.util.Selector.query("#content form input, #content form textarea");
        for (var i=0; i<fields.length; i++){
            var el = fields[i];
            var value = '';
            if (el.type != 'submit') {
                if (el.type == 'checkbox'){
                    value = el.checked ? el.value : '';
                } else if (el.type == 'radio'){
                    value = el.value;
                } else {
                    value = el.value;
                }
                postArray.push(encodeURIComponent(el.name) +"="+ encodeURIComponent(value));
            }
        }
        var selects = YAHOO.util.Selector.query("#content form select");
        for (var i=0; i<selects.length; i++){
            var el = selects[i];
            for (var j=0; j<el.options.length; j++) {
                if (el.options[j].selected) {
                    postArray.push(encodeURIComponent(el.name) +"="+ encodeURIComponent(el.options[j].value));
                }
            }
        }
        var postData = postArray.join("&");
        var callback = {
          success: function(obj) {},
          failure: function(obj) {document.write(obj.responseText)}
        };
        YAHOO.util.Connect.asyncRequest('POST', '.', callback, postData);
    }
}

//YAHOO.util.Event.onDOMReady(sorl.curator.cont.init, sorl.curator.cont, true);
